package com.lovo.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.system.dto.JournalDto;
import com.lovo.system.mapper.JournalMapper;
import com.lovo.system.service.IJournalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JournalServiceImpl extends ServiceImpl<JournalMapper, JournalDto> implements IJournalService {

    @Autowired
    JournalMapper journalMapper;

    @Override
    public IPage<JournalDto> cutByItem(int curPage, int pageSize, String startTime, String endTime) {
        QueryWrapper qw = new QueryWrapper();
        if (startTime != null && !"".equals(startTime)) {
            qw.ge("journal_date", startTime);
        }
        if (endTime != null && !"".equals(endTime)) {
            qw.le("journal_date", endTime);
        }
        return journalMapper.selectPage(new Page<>(curPage, pageSize), qw);
    }

    @Override
    public void insertJournal(JournalDto journalDto) {
        journalMapper.insert(journalDto);
    }

}
